import sys
from PySide6 import QtWidgets
from PySide6.QtWidgets import QApplication, QWidget
from WidgetElementsParams.StraightCirclePipeWidget import StraightCirclePipeWidget as scpw
from WidgetElementsParams.StraightRectPipeWidget import StraightRectPipeWidget as srpw
import styles.styles_elements as styles


class StraightPipeWidget(QWidget):
    def __init__(self, parent=None):
        super(StraightPipeWidget, self).__init__(parent)

        self.circle_pipe = scpw()
        self.rect_pipe = srpw()

        # Создание стэка виджетов
        self.stacked_widget = QtWidgets.QStackedWidget()
        self.stacked_widget.addWidget(self.circle_pipe)
        self.stacked_widget.addWidget(self.rect_pipe)

        # Создание выпадающего списка типа сечений
        self.choose_type_cross_sec_cb = QtWidgets.QComboBox()

        self.choose_type_cross_sec_cb.setObjectName('cross_section')
        self.choose_type_cross_sec_cb.setStyleSheet(styles.QComboBox_StyleSheet)
        self.choose_type_cross_sec_cb.setPlaceholderText('Выбор сечения')
        self.choose_type_cross_sec_cb.addItems(('Круглое', 'Прямоугольное'))

        # Отображение виджетов в окне
        self.vlayout = QtWidgets.QVBoxLayout()
        self.vlayout.addWidget(self.choose_type_cross_sec_cb)
        self.vlayout.addWidget(self.stacked_widget)
        self.setLayout(self.vlayout)

        self.choose_type_cross_sec_cb.currentIndexChanged.connect(self.stacked_widget.setCurrentIndex)

    def get_cross_section(self):
        return {self.choose_type_cross_sec_cb: self.choose_type_cross_sec_cb.currentText()}

    def get_params_element(self):
        params_pipe = self.circle_pipe.get_params_element()
        if self.choose_type_cross_sec_cb.currentText() == 'Круглое':
            params_pipe = self.circle_pipe.get_params_element()
        elif self.choose_type_cross_sec_cb.currentText() == 'Прямоугольное':
            params_pipe = self.rect_pipe.get_params_element()
        params_pipe.update(self.get_cross_section())
        return params_pipe

    def get_name_params_element(self):
        if self.choose_type_cross_sec_cb.currentText() == 'Круглое':
            name_params_pipe = self.circle_pipe.get_name_params_element()
            return name_params_pipe
        elif self.choose_type_cross_sec_cb.currentText() == 'Прямоугольное':
            name_params_pipe = self.rect_pipe.get_name_params_element()
            return name_params_pipe


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = StraightPipeWidget()
    window.show()
    sys.exit(app.exec())
